//
//  HelpModel.m
//  RainbowFM
//
//  Created by Kratos on 14/12/24.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "HelpModel.h"

#import "HelpAPI.h"

@implementation HelpModel

+(instancetype)sharedModel
{
    static HelpModel *helpModel = nil;
    static dispatch_once_t once;
    
    dispatch_once(&once, ^{
        helpModel = [[HelpModel alloc] init];
    });
    
    return helpModel;
}

/**
 * 便民信息
 * @param type 类型 1 失物， 2 寻人, 3 节目推荐信息
 * @param currentPage 当前页码
 * @param pageSize 每页显示记录数
 * @return <#return value description#>
 * @author Kratos
 */
-(void)fetchHelpListWithType:(NSString *)type
                 currentPage:(int)currentPage
                    pageSize:(int)pageSize
                      result:(void (^)(NSArray *list, NSString *msg))res
{
    HelpAPI *api = [HelpAPI new];
    [api fetchHelpListWithType:type currentPage:_F(@"%d",currentPage) pageSize:_F(@"%d",pageSize) result:^(NSArray *list, NSString *msg) {
        NSMutableArray *itemlist = [NSMutableArray array];
        for (NSDictionary *dic in list) {
            HelpItem *item = [[HelpItem alloc]initWithDataDic:dic];
            [itemlist addObject:item];
        }
        
        res(itemlist,msg);
    }];
}


/**
 * 添加便民信息
 * @param desct 简单描述
 * @param detilDesc 详细描述
 * @param picUrl 图片地址, 没有传 “”
 * @param meUrl 媒体地址, 没有传 “”
 * @param type 类型 1 失物， 2 寻人
 * @return <#return value description#>
 * @author Kratos
 */
-(void)addHelpInfoWithDesct:(NSString *)desct
                  detilDesc:(NSString *)detilDesc
                     picUrl:(NSString *)picUrl
                      meUrl:(NSString *)meUrl
                       type:(NSString *)type
                     result:(void (^)(BOOL success, NSString *msg))res
{
    HelpAPI *api = [HelpAPI new];
    [api addHelpInfoWithDesct:desct detilDesc:detilDesc picUrl:picUrl meUrl:meUrl type:type result:^(BOOL success, NSString *msg) {
        res(success,msg);
    }];
}

@end

@implementation HelpItem

-(NSDictionary *)attributeMapDictionary
{

    return @{@"programId":@"id",
             @"DESCT":@"DESCT",
             @"DETILDESC":@"DETILDESC",
             @"PICURL":@"PICURL",
             @"MEURL":@"MEURL",
             @"TYPE":@"TYPE",
             @"CREATEDATE":@"CREATEDATE",
             @"CREATEUSER":@"CREATEUSER",
             @"totalResults":@"totalResults"};
}

-(NSString *)PICURL
{
    if (_PICURL) {
        if (![_PICURL isKindOfClass:[NSNull class]]) {
            return _PICURL;
        }else{
            return nil;
        }
    }else{
        return nil;
    }
}

-(NSString *)MEURL
{
    if (_MEURL) {
        if (![_MEURL isKindOfClass:[NSNull class]]) {
            return _MEURL;
        }else{
            return nil;
        }
    }else{
        return nil;
    }
}

@end
